<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){
            jQuery.validator.addMethod("detail_required", function(value, element, param) {
                var returnVal = true;				
				if(CKEDITOR.instances.activity_detail.getData()==''){
					returnVal = false;
				}
				return returnVal;
           	}, jQuery.validator.messages.detail_required);
											
            $("#Form").validate({
				ignore: "",
                rules: {
					activity_subject: "required",
					activity_brief: "required",
					activity_detail: {
						detail_required:true
					},
					activity_tag: "required"
                },
                showErrors: function(errorMap, errorList){
                    var messages='';
                    for (var i = 0; i < errorList.length; i++) {					
                        messages += '- '+errorList[i].message+'\n';
                    }
                    if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
                    //this.defaultShowErrors();
                } ,
                submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					if(queueSize > 0){
						$('#file_upload').uploadifyUpload();
					} else { success_file = true; }				
					var interval = setInterval(function() {
					    if (success_file) {
					        clearInterval(interval);
							//Send Form
					        document.forms["Form"].submit();
					    }
					}, 100);
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,					
                messages: {
					activity_subject: "<?php echo lang('activity_subject');?>",
					activity_brief: "<?php echo lang('activity_brief');?>",
					activity_detail: {
						detail_required: "<?php echo lang('activity_detail');?>"
					},					
					activity_tag: "<?php echo lang('activity_tag');?>"	
                }
            });	
			
            /*Images Upload*/
            var queueSize = 0;		
            var imgname= new Array();
			var success_file = false;					
            $('#file_upload').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : true,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store',
					    name: 'uploadify_store',
						value: imgname
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file=true;
                },
                'onSelectOnce' : function (event,data) {
                    queueSize = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize = data.fileCount;
                }						
            });			
			//DateTime Picker
			$('.datetime').datetimepicker({
				dateFormat:'dd/mm/yy',
				timeFormat:'hh:mm',
				separator:' ',
			    changeMonth : true,
			    changeYear : true,
				yearRange: 'c+nn:+1',
				maxDate: '-1d',
				showHour: true,		
				showMinute: true,
				showTime: true		
			});
			//ColorBox Iframe
			$('.search_tools').colorbox({iframe:true, innerWidth:300, innerHeight:600, right:0, opacity:0.4});		
        });
    })(jQuery);	
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>	
						<tr>
							<th scope="row"><?php echo lang('is_publish');?></th>
							<td>
								<input type="radio" name="is_publish" value="1" checked="checked"/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" /> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('is_show_sidebar');?></th>
							<td>
								<input type="radio" name="is_show_sidebar" value="1" checked="checked"/> <?php echo lang('yes');?>
								<input type="radio" name="is_show_sidebar" value="0" /> <?php echo lang('no');?>
							</td>
						</tr>						
						<tr>
							<th scope="row"><?php echo lang('activity_date_end');?></th>
							<td><input type="text" name="activity_date_end" id="activity_date_end" class="medium-text datetime" value="<?php echo date('d/m/Y').' 23:59';?>" readonly="readonly"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('activity_auth_date');?></th>
							<td><input type="text" name="activity_auth_date" id="activity_auth_date" class="medium-text datetime" value="<?php echo date('d/m/Y').' 23:59';?>" readonly="readonly"/></td>
						</tr>																
						<tr>
							<th scope="row"><?php echo lang('activity_subject');?></th>
							<td><input type="text" name="activity_subject" id="activity_subject" class="regular-text" /></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('activity_brief');?></th>
							<td>
								<textarea name="activity_brief" id="activity_brief" rows="5" class="regular-text"></textarea>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('activity_detail');?></th>
							<td><?php echo display_ckeditor('activity_detail','',array('toolbar' => 'Medium','skin' => 'v2','width' => '550px','height' => '200px'),false); ?></td>
						</tr>											
						<tr>
							<th scope="row"><?php echo lang('activity_image');?></th>
							<td><input type="file" name="file_upload" id="file_upload"/></td>
						</tr>																									
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_add');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->